package org.example.udemo1.service;

import org.example.udemo1.dao.BookDao;
import org.example.udemo1.model.BookInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component//表示将BookService的对象交给Spring管理了(Spring帮你创建了该对象放到容器中了)
public class BookService {
    @Autowired //表示从spring中取到对象放到要用的地方
    private BookDao bookDao;

    public List<BookInfo> getList(){
//        BookDao bookDao = new BookDao();
//从数据库中查询,先mock(模拟)一些数据

        List<BookInfo> bookInfos = bookDao.mockData();
        for(BookInfo bookInfo : bookInfos){
            if(bookInfo.getStatus() == 1){
                bookInfo.setStatusCN("可借阅");//这里的设置是为了方便后面,但不合理,正常后端是返回数字0或1
            }else{
                bookInfo.setStatusCN("不可借阅");
            }
        }
        return bookInfos;
    }
}



